<?php

namespace App\Models;

use App\Constant;
use Illuminate\Database\Eloquent\Model;

class OrderDetail extends Model
{
    
    public function getVariantionAttribute($value)
    {
        return $this->attributes['variation'];
    }
    
    public function setVariantionAttribute($value)
    {
        $this->attributes['variation'] = $value;
        return $this;
    }
    
    public function order()
    {
        return $this->belongsTo(Order::class);
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function pickup_point()
    {
        return $this->belongsTo(PickupPoint::class);
    }

    public function refund_request()
    {
        return $this->hasOne(RefundRequest::class);
    }

    public function affiliate_log()
    {
        return $this->hasMany(AffiliateLog::class);
    }

    public function profitlog()
    {
        return $this->hasOne(BalanceLogModel::class, 'trade_id', 'id')->where('type', Constant::BALANCE_LOG_TYPE_ORDER_REBATE);
    }

    public function seller()
    {
        return $this->belongsTo(User::class, 'seller_id', 'id');
    }
}
